#ifndef SERVER_H
#define SERVER_H

#include <memory>
#include <string>

// 全局辅助函数声明
std::string createResponse(const std::string& status, const std::string& message, const std::string& data);

class Database;
class Auth;
class CourseManager;

class Server {
private:
    std::unique_ptr<Database> db_;
    std::unique_ptr<Auth> auth_;
    std::unique_ptr<CourseManager> courseManager_;

    int server_fd_;
    std::string handleLogin(const std::string& request);
    std::string handleGetCourses();
    std::string handleGetStudentInfo(const std::string& request);
    std::string handleGetStudentCourses(const std::string& request);
    std::string handleSelectCourse(const std::string& request);
    std::string handleDropCourse(const std::string& request);

    // 管理员功能
    std::string handleGetAllStudents();
    std::string handleGetAllTeachers();
    std::string handleGetAllCourseSelections();

    // 教师功能
    std::string handleGetTeacherCourses(const std::string& request);
    std::string handleGetCourseStudents(const std::string& request);

    std::string handleIndex();

public:
    Server();
    ~Server();
    void run(int port = 8080);
    std::string processRequest(const std::string& request);
};

#endif // SERVER_H
